package com.ymx.darling.type;

import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.Objects;

public class LocalDateHandler implements TypeHandler<LocalDate> {
    @Override
    public LocalDate getResult(ResultSet resultSet, int columIndex) throws SQLException {
        Date date = resultSet.getDate(columIndex);
        return Objects.isNull(date) ? null : date.toLocalDate();
    }

    @Override
    public void setParameter(PreparedStatement statement, LocalDate value, int index) throws SQLException {
        statement.setDate(index, Date.valueOf((value)));
    }
}
